using Infrastructure;
using Infrastructure.Attribute;
using Mapster;
using SqlSugar;
using ZR.Model;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Repository;
using ZR.ServiceCore.Services.IService;

namespace ZR.ServiceCore.Services
{
    /// <summary>
    /// 测试表2服务
    /// </summary>
    [AppService(ServiceType = typeof(ISheetTest2Service), ServiceLifetime = LifeTime.Transient)]
    public class SheetTest2Service : BaseService<SheetTest2>, ISheetTest2Service
    {
        /// <summary>
        /// 分页查询测试表2列表
        /// </summary>
        /// <param name="queryDto">查询条件</param>
        /// <param name="pager">分页参数</param>
        /// <returns></returns>
        public PagedInfo<SheetTest2> SelectSheetTest2List(SheetTest2QueryDto queryDto, PagerInfo pager)
        {
            var exp = Expressionable.Create<SheetTest2>();
            exp.AndIF(queryDto.Id.HasValue && queryDto.Id > 0, x => x.Id == queryDto.Id);
            exp.AndIF(!string.IsNullOrEmpty(queryDto.CoordinatesX), x => x.CoordinatesX.Contains(queryDto.CoordinatesX));
            exp.AndIF(!string.IsNullOrEmpty(queryDto.CoordinatesY), x => x.CoordinatesY.Contains(queryDto.CoordinatesY));
            exp.AndIF(!string.IsNullOrEmpty(queryDto.Speed), x => x.Speed.Contains(queryDto.Speed));
            exp.AndIF(!string.IsNullOrEmpty(queryDto.Direction), x => x.Direction.Contains(queryDto.Direction));
            // 过滤掉包含-9999.00的数据（任何一个字段等于-9999.00就过滤掉整行）
            exp.And(w => w.CoordinatesX != "-9999.00" &&
                        w.CoordinatesY != "-9999.00" &&
                        w.Speed != "-9999.00" &&
                        w.Direction != "-9999.00");

            var query = Queryable()
                .Where(exp.ToExpression());

            return query.ToPage(pager);
        }

        /// <summary>
        /// 根据ID查询测试表2
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        public SheetTest2 SelectSheetTest2ById(int id)
        {
            return Queryable()
                .Where(x => x.Id == id)
                .First();
        }

        /// <summary>
        /// 添加测试表2
        /// </summary>
        /// <param name="addDto">添加对象</param>
        /// <returns></returns>
        public int AddSheetTest2(SheetTest2AddDto addDto)
        {
            var entity = addDto.Adapt<SheetTest2>();

            return Insert(entity);
        }

        /// <summary>
        /// 修改测试表2
        /// </summary>
        /// <param name="updateDto">修改对象</param>
        /// <returns></returns>
        public int UpdateSheetTest2(SheetTest2UpdateDto updateDto)
        {
            var entity = updateDto.Adapt<SheetTest2>();

            return Update(entity);
        }

        /// <summary>
        /// 删除测试表2
        /// </summary>
        /// <param name="ids">主键ID数组</param>
        /// <returns></returns>
        public int DeleteSheetTest2(int[] ids)
        {
            return Delete(ids);
        }
    }
}
